#include "ddarray.h"
#include <crtdbg.h>
#define _CRTDBG_MAP_ALLOC

void fill_ar (DDArray * ar, Pointer value)
{
	size_t i, j;
	int *c;
	for (j=0; j<ar->Y; j++)
	{
		for(i=0; i<ar->X; i++)
		{
			c = (int*)find_element(ar, i, j);
			*c = value;
		}
	}
}

void fill_ar_numb (DDArray * ar)
{
	size_t i, j;
	int *c;
	for (j=0; j<ar->Y; j++)
	{
		for(i=0; i<ar->X; i++)
		{
			c = (int*)find_element(ar, i, j);
			*c = 10*j+i;
		}
	}
}

void print_ar ( DDArray * ar)
{
	size_t i, j;
	for(j=0; j<ar->Y; j++)
	{
		for (i=0; i<ar->X; i++)
		{
            printf("%d ", *(int*)find_element(ar, i, j));
		}
		printf("\n");
	}
	printf("\n");
}

put_value ( DDArray * ar, Pointer value, size_t i, size_t j )
{
	int *c;
	c = (int*)find_element(ar, i, j);
	*c = value;
}

int main () {
	DDArray *p;
	DDArray *b;
	int c=1;
	int i, j;

	p = new(&_DDArray, 8, 8, sizeof(int));
	b = new(&_DDArray, 3, 3,  sizeof(int));

	c=1;
	print_ar (p);

	c=2;
	fill_ar_numb (b);
	print_ar (b);

	c=3;
	fill_ar ( p, c);
	print_ar (p);

	c=4;
	put_value (p, c, 3, 5);
	print_ar (p);

	resize( p, 10, 10);
	print_ar (p);

	c=7;
	fill_ar (p,c);
	print_ar (p);

	copy ( b, p, 3, 3);
	print_ar (p);

	//fill_ar_numb(p);
	print_ar(p);

	resize (p, 6, 7);
	print_ar (p);

	delete(p);
	delete(b);

	_CrtDumpMemoryLeaks();
	system("pause");
}